<template>
  <div class="app-container">
      <el-form :inline="true" :model="listQuery" class="demo-form-inline" @submit.native.prevent>
        <el-form-item label="活动名称">
          <el-input v-model="listQuery.q_actFullName" size="small"></el-input>
        </el-form-item>
        <el-form-item label="第一档满额">
          <el-input v-model="listQuery.q_firstFull" size="small"></el-input>
        </el-form-item>
        <el-form-item label="使用日期">
          <el-date-picker
            v-model="listQuery.q_time"
            type="datetime"
            placeholder="选择日期时间" size="small">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            class="toolbar-lable-right"
            v-model="listQuery.q_status"
            placeholder="请选择" size="small">
            <el-option
              v-for="item in actStatus"
              :label="item.name"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道">
          <el-select
            class="toolbar-lable-right"
            v-model="listQuery.q_channel"
            placeholder="请选择" size="small">
            <el-option
              v-for="item in channel"
              :label="item.name"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商家">
          <el-select
            class="toolbar-lable-right"
            v-model="listQuery.q_sellerId"
            placeholder="请选择"
            size="small"
          >
            <el-option
              v-for="item in sellers"
              :label="item.name"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="this.getList">查询</el-button>
          <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table
        ref="singleTable"
        v-loading="listLoading"
        :data="dataList"
        border
        fit
        highlight-current-row
        @current-change="handleCurrentChange"
        style="width: 100%">
        <el-table-column
          type="index"
          align="center"
          width="50">
        </el-table-column>
        <el-table-column property="sellerName" width="200" label="店铺名称"></el-table-column>
        <el-table-column property="actFullName" width="200" label="满减活动名称"></el-table-column>
        <el-table-column property="firstFull" width="200" label="第一档满额"></el-table-column>
        <el-table-column property="firstDiscount" width="200" label="第一档减免额"></el-table-column>
        <el-table-column property="secondFull" width="200" label="第二档满额"></el-table-column>
        <el-table-column property="secondDiscount" width="200" label="第二档减免额"></el-table-column>
        <el-table-column property="thirdFull" width="200" label="第三档满额"></el-table-column>
        <el-table-column property="thirdDiscount" width="200" label="第三档减免额"></el-table-column>
        <el-table-column property="startTime" width="200" label="开始时间"></el-table-column>
        <el-table-column property="endTime" width="200" label="结束时间"></el-table-column>
        <el-table-column property="channel" width="150" label="应用渠道">
          <template slot-scope="scope">
            {{ codeBox.CHANNEL[scope.row.channel] }}
          </template>
        </el-table-column>
        <el-table-column property="status" width="150" label="状态">
          <template slot-scope="scope">
            {{ codeBox.ACT_STATUS[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column property="updateUserName" width="200" label="最后修改人"></el-table-column>
        <el-table-column property="updateTime" width="200" label="最后修改时间"></el-table-column>
        <el-table-column property="createUserName" width="200" label="创建用户"></el-table-column>
        <el-table-column property="createTime" width="200" label="创建时间"></el-table-column>
        <el-table-column property="auditOpinion" width="150" label="审核意见"></el-table-column>
        <el-table-column property="remark" width="200" label="活动描述"></el-table-column>
        <el-table-column fixed="right" label="操作" width="70" align="center">
          <template slot-scope="scope">
            <el-button @click="auditRow(scope.row)" type="text" size="small">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
import { listActFull } from '@/api/promotionbasics'
import Pagination from '@/components/Pagination'
import { Message } from 'element-ui'
import { getCodeManager,codeToArray, getSellers} from '@/api/all'
export default {
  name: 'exchangelist',
  components: { Pagination },
  data() {
    return {
      currentRow: null,
      dataList: [],
      actStatus: [],
      channel: [],
      sellers: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        q_actFullName: '',
        q_time: '',
        q_status: '',
        q_channel: '',
        q_sellerId: ''
      }
    }
  },
  created() {
    getCodeManager('ACT_STATUS,CHANNEL,COUPON_TYPE', () => {
      this.actStatus = codeToArray('ACT_STATUS');
      this.channel = codeToArray('CHANNEL');
    })
    this.getList()
    getSellers().then(response => {
      this.sellers=[
        ...response.data.rows.map((item)=>{return  {
          name:item.sellerName,
          value:item.id
        }})
      ]
    })
  },
  methods:{
    handleCurrentChange(val) {
      // 选中当前行数据
      this.currentRow = val
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      listActFull(this.listQuery).then(response => {
        this.dataList = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    reset() {
      this.listQuery = {
        page: 1,
        limit: 20,
        q_actFullName: '',
        q_time: '',
        q_status: '',
        q_channel: '',
        q_sellerId: ''
      }
      this.getList()
    },
    auditRow(currentRowDo){
      if(currentRowDo.status != 2) {
        Message.error('只有提交审核状态才能进行审核操作')
        return
      }
      this.$router.push({
        path: "/promotionbasics/actfullaudit",
        query: { id: currentRowDo.id }
      });
    }
  }
}
</script>

<style>
</style>
